﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace LuDo.PitEditor
{
    public partial class BBCodeEditor : Form
    {
        public string TaggedText { get; private set; }
        public DateTime FileCreationDate { get; private set; }
        public string FileName { get; private set; }

        public BBCodeEditor(string Text)
        {
            InitializeComponent();
            this.FileCreationDate = DateTime.Today;
            txtBBCode.Font = PitEditor.Properties.Settings.Default.EditorFont;
            txtBBCode.WordWrap = PitEditor.Properties.Settings.Default.EditorWrapText;
            txtBBCode.Text = Text;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            this.TaggedText = txtBBCode.Text;
        }

        private void btnFile_Click(object sender, EventArgs e)
        {
            OpenTextFile.FileName = "";
            OpenTextFile.InitialDirectory = Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
            DialogResult res = OpenTextFile.ShowDialog();
            if (res == DialogResult.OK)
            {
                string name = System.IO.Path.GetFileName(OpenTextFile.FileName);
                DateTime creation = File.GetCreationTime(OpenTextFile.FileName);
                try
                {
                    txtBBCode.Text = System.IO.File.ReadAllText(OpenTextFile.FileName, Encoding.Default);
                    this.FileName = name;
                    this.FileCreationDate = creation;
                }
                catch
                {
                    string msg = String.Format("Importazione dell'articolo -{0}- fallita.", name);
                    MessageBox.Show(msg);
                }
            }
        }
    }
}
